/***********************************************************************
 * Module:  PatientDto.java
 * Author:  Vanil
 * Purpose: Defines the Class PatientDto
 ***********************************************************************/
package personal;

import db.dao.*;
import db.dto.*;
import db.exceptions.*;
import db.jdbc.*;

import java.util.ArrayList;
import java.util.Collection;

public class Patient extends Person {

    public Patient(PatientDto dto) {
        super(dto);
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);    //To change body of overridden methods use File | Settings | File Templates.
    }

    /** @pdOid b1d8c0d3-d4c4-4592-8495-44588d3ab8f9 */
   public void viewAllTasks() {
      // TODO: implement
   }
       @Override
       public String toString() {
           return this.getName();    //To change body of overridden methods use File | Settings | File Templates.
       }
    public Patient() {
    }


   public java.util.Collection<Intake> getIntakes() throws IntakeDaoException {
       int idPerson = ((PatientDto)dto).getIdPerson();
       IntakeDao dao = new IntakeDaoImpl();
       IntakeDto[] intakeDtos = dao.findWhereIdPatientEquals(idPerson);
       Collection<Intake> intakes = new ArrayList<Intake>();
       for(IntakeDto intakeDto:intakeDtos)
       {
           intakes.add(new Intake(intakeDto));
       }
      return intakes;
   }

    public String getIllnessHistory() {
        return ((PatientDto)dto).getIllnesshistory();
    }

    public Collection<Prescription> getPrescriptions() throws PrescriptionDaoException {
        PrescriptionDao dao = new PrescriptionDaoImpl();
        PrescriptionDto[] prescriptionDtos = dao.findByPatient(dto.getIdPerson());
        Collection<Prescription> prescriptions = new ArrayList<Prescription>();
        for(PrescriptionDto prescriptionDto: prescriptionDtos )
        {
            prescriptions.add(new Prescription(prescriptionDto));
        }
        return prescriptions;

    }

    public void setIllnessHistory(String illnessHistory) throws PatientDaoException {
        ((PatientDto)dto).setIllnesshistory(illnessHistory);
    }

    private void update() throws PatientDaoException {
        PatientDao dao = new PatientDaoImpl();
        dao.update(dto.getIdPerson(),(PatientDto)dto);
    }

    public void addPrescription(Prescription prescription) throws PatientDaoException {

    }

    /**
     * @param oldIntake */
   public void removeIntake(Intake oldIntake) throws IntakeDaoException {
        IntakeDao dao = new IntakeDaoImpl();
        dao.delete(oldIntake.dto.getIdIntake());

   }


   public Doctor getDoctor() throws DoctorDaoException {
       DoctorDao docDao = new DoctorDaoImpl();
       DoctorDto docDto = docDao.findByPrimaryKey(((PatientDto) dto).getIdDoctor());
       return new Doctor(docDto);
   }

   public void setDoctor(Doctor newDoctor) throws PatientDaoException {
        ((PatientDto) dto).setIdDoctor(newDoctor.getIdPerson());
   }

   public Nurse getNurse() throws NurseDaoException {
       if(((PatientDto) dto).isIdNurseNull())
           return null;
       NurseDao nurseDao = new NurseDaoImpl();
       NurseDto nurseDto = nurseDao.findByPrimaryKey(((PatientDto) dto).getIdNurse());
       return new Nurse(nurseDto);
   }


   public void setNurse(Nurse newNurse) throws PatientDaoException {
        if(newNurse !=null)
            ((PatientDto) dto).setIdNurse(newNurse.getIdPerson());
        else
            ((PatientDto) dto).setIdNurseNull(true);
   }
    public String getName()
    {
        return super.getName();
    }
    public int getIdPerson()
    {
        return super.getIdPerson();
    }
    

}